def greet_user(username):
    '''显示简单的问候'''
    print('hello, '+username.title()+"!")

greet_user("xujianfeng")



#编写函数时，可给每个形参指定默认值
def describe_pet(pet_name, animal_type='dog'):
#显示宠物的信息
    print("\nI have a " + animal_type + ".")
    print("My " + animal_type + "'s name is " + pet_name.title() + ".")
describe_pet(pet_name='willie')
describe_pet('bule','cat')


#返回值
def get_formatted_name(first_name, last_name): 
    """返回整洁的姓名"""
    full_name = first_name + ' ' + last_name 
    return full_name.title()

musician = get_formatted_name('jimi', 'hendrix') 
print(musician)

#函数可返回任何类型的值，包括列表和字典等较复杂的数据结构
def build_person(first_name, last_name): 
    """返回一个字典，其中包含有关一个人的信息"""
    person = {'first': first_name, 'last': last_name}
    return person
musician = build_person('jimi', 'hendrix') 
print(musician)



#向函数传递列表
def greet_users(names): 
    """向列表中的每位用户都发出简单的问候""" 
    for name in names:
        msg = "Hello, " + name.title() + "!" 
        print(msg)

usernames = ['hannah', 'ty', 'margot'] 
greet_users(usernames)


#传递任意数量的实参
def make_pizza(*toppings): 
    """打印顾客点的所有配料""" 
    print(toppings)
make_pizza('pepperoni')
make_pizza('mushrooms', 'green peppers', 'extra cheese')


'''
形参名*toppings 中的星号让Python创建一个名为toppings的空元组，
并将收到的所有值都封装到这个元组中。
'''



#两个星号让Python创建一个空字典，并将收到的所有名称—值对都封装到这个字典中。
def build_profile(first, last, **user_info): 
    """创建一个字典，其中包含我们知道的有关用户的一切""" 
    profile = {}
    profile['first_name'] = first
    profile['last_name'] = last
    for key, value in user_info.items(): 
        profile[key] = value
    return profile

user_profile = build_profile('albert', 'einstein', location='princeton',field='physics')
print(user_profile)


#导入整个模块
import pizza
pizza.make_pizza(16,'pepperoni','mushrooms')

#导入整个模块
import pizza as mp
mp.make_pizza(11,'oooo')


#导入特定函数
from pizza import make_pizza
make_pizza(16,'pepperoni','mushrooms')







